import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter/material.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';

///************************
/// @auther nb
/// @function 公告列表
/// @创建日期 2019/8/12 9:29
///************************

class NoticeList extends StatefulWidget {
  @override
  _NoticeListState createState() => _NoticeListState();
}

class _NoticeListState extends State<NoticeList> {
  List datas = [
    {
      "title": "点击领取支付宝红包",
      "isNew": true,
      "time": "2019年7月1日",
      "content": "打开支付宝首页搜5219384领红包，点击领取支付宝红包,打开支付宝首页搜5219384领红包，点击领取支付宝红包",
    },
    {
      "title": "点击领取支付宝红包",
      "isNew": true,
      "time": "2019年7月1日",
      "content": "打开支付宝首页搜5219384领红包，点击领取支付宝红包,打开支付宝首页搜5219384领红包，点击领取支付宝红包",
    },
    {
      "title": "点击领取支付宝红包",
      "isNew": false,
      "time": "2019年7月1日",
      "content": "打开支付宝首页搜5219384领红包，点击领取支付宝红包,打开支付宝首页搜5219384领红包，点击领取支付宝红包",
    }
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colours.c243,
        appBar: UiUtils.appBar(context, "公告列表"),
        body: Column(
          children: <Widget>[
            UiUtils.dividerWidget(ScreenUtil().setWidth(20)),
            Expanded(
              flex: 1,
              child: EasyRefresh(
                  onRefresh: () {},
                  onLoad: () {},
                  child: ListView.builder(
                      itemCount: datas.length,
                      itemBuilder: (BuildContext context, int index) {
                        return getItem(datas[index]);
                      })),
            )
          ],
        ));
  }

  Widget getItem(data) {
    return GestureDetector(
      onTap: () {
        NavigatorUtils.push(context, Routes.noticeDetails);
      //  Application.router.navigateTo(context, Routes.noticeDetails);
      },
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(30), ScreenUtil().setWidth(10), 0, 0),
        child: Column(
          children: <Widget>[
            Container(
              child: Row(
                children: <Widget>[
                  Expanded(
                      flex: 1,
                      child: Text(
                        "${data["title"]}",
                        style: TextStyles.custom(
                            28, Colours.appC1, Font.PingFangBlod),
                      )),
                  data["isNew"]
                      ? Container(
                          alignment: Alignment.center,
                          width: ScreenUtil().setWidth(46),
                          height: ScreenUtil().setWidth(28),
                          decoration: BoxDecoration(
                            // 边色与边宽度
                            color: Color(0xFFe3393c),
                            // 底色
                            borderRadius: new BorderRadius.circular(7), // 圆角度
                          ),
                          child: Text(
                            "新",
                            style: TextStyles.custom(
                                22, Colors.white, Font.PingFangMedium),
                          ),
                        )
                      : Container(),
                  Container(
                    margin: EdgeInsets.only(
                        left: 10, right: ScreenUtil().setWidth(30)),
                    child: Text(
                      "${data["time"]}",
                      style: TextStyles.custom(
                          24, Color(0xFF999999), Font.PingFangMedium),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(
                  right: ScreenUtil().setWidth(30),
                  top: ScreenUtil().setWidth(10),
                  bottom: ScreenUtil().setWidth(10)),
              child: Text(
                "${data["content"]}",
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyles.custom(
                    24, Color(0xFF999999), Font.PingFangMedium),
              ),
            ),
            Container(
              child: Row(
                children: <Widget>[
                  Text(
                    "查看详情",
                    style: TextStyles.custom(
                        24, Color(0xFF666666), Font.PingFangMedium),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 5),
                    child: Image.asset(Utils.getImgPath("icon_right"),
                        width: ScreenUtil().setWidth(20),
                        height: ScreenUtil().setWidth(20)),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: ScreenUtil().setWidth(20)),
              child: UiUtils.dividerWidget(1),
            )
          ],
        ),
      ),
    );
  }
}
